local Lua__yishishengyan = fk.CreateSkill {

  name = "Lua__yishishengyan",

  tags = { Skill.Compulsory, Skill.Hidden },

}

Fk:loadTranslationTable{
    
    ["Lua__yishishengyan"] = "伊始盛宴",
    [":Lua__yishishengyan"] = "隐匿技，锁定技，当你登场时，若你因“-《( 目 )》-”复活过，你失去其一回合，然后其他角色须选择一项：1：将随机一半向上取整的手牌交给你；2：失去所有体力。",
    ["#yishi-choice"] = "伊始盛宴：请选择一项",
    ["$Lua__yishishengyan1"] = "你会听到成千上万人的笑声，伴随着天空的敞开。",
    ["$Lua__yishishengyan2"] = "你会听到号角奏响欢乐的旋律，生命的鲜血将倾泻在我们所有人身上。",
    ["yishistl1"] = "将随机一半向上取整的手牌交给其",
    ["yishistl2"] = "失去所有体力",
}

local U = require "packages.utility.utility"
local M = require "packages.internetMEME.record.INTTE"

Lua__yishishengyan:addEffect(U.GeneralAppeared, {
    anim_type = "control",
    can_trigger = function(self, event, target, player, data)
        return target == player and player:hasSkill(Lua__yishishengyan.name)
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        if player:getMark("@@mu_death") == 1 then
          room:setPlayerMark(player, "@@mu_death", 0)
          M.removeAllSkills(player, room, "Lua__yishishengyan", "Lua__yishishengyan-turn")
        end
        -- 对每个其他角色执行选择
        for _, p in ipairs(room:getOtherPlayers(player)) do
            -- 计算需要给出的牌数
            local hand_cards = p:getCardIds(Player.Hand)
            local num_cards = math.ceil(#hand_cards / 2)
            -- 让玩家选择
            local choices = {"yishistl2"}
            if not p:isKongcheng() then
              table.insert(choices, "yishistl1")
            end
            local choice = player.room:askToChoice(p, {
              choices = choices,
              skill_name = Lua__yishishengyan.name,
              prompt = "#yishi-choice",
            })

            if choice == "yishistl1" then
                    -- 随机选择一半的手牌
                    local to_give = {}
                    local available = table.clone(hand_cards)
                    for i = 1, num_cards do
                        local idx = math.random(1, #available)
                        table.insert(to_give, available[idx])
                        table.remove(available, idx)
                    end
                    room:moveCardTo(to_give, Card.PlayerHand, player, fk.ReasonGive, Lua__yishishengyan.name, "", true)
            else
                -- 选择失去所有体力
                room:loseHp(p, p.hp, Lua__yishishengyan.name)
            end
        end
    end,
})
Lua__yishishengyan:addEffect(fk.TurnEnd, {
  refresh_events = {fk.TurnEnd},
    can_refresh = function(self, event, target, player, data)
      return player.tag["Lua__yishishengyan"] and #player.tag["Lua__yishishengyan"] > 0 and (event == fk.TurnEnd or target == player)
  end,
  on_refresh = function(self, event, target, player, data)
      M.restoreRemovedSkills(player, player.room, "Lua__yishishengyan", "Lua__yishishengyan-turn")
  end,
})

return Lua__yishishengyan